package com.luofan.controller;


import com.github.pagehelper.PageInfo;
import com.luofan.common.result.Result;
import com.luofan.common.result.ResultCodeEnum;
import com.luofan.entity.dto.PageDTO;
import com.luofan.entity.po.Notice;
import com.luofan.entity.vo.NoticeUserVO;
import com.luofan.entity.vo.NoticeVO;
import com.luofan.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 公告表 前端控制器
 * </p>
 *
 * @author 
 * @since 2025-03-26
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    //管理员 发布通知
    @PostMapping
    public Result<String> createNotice(@RequestBody Notice notice) {
        ResultCodeEnum resultCodeEnum = noticeService.createNotice(notice);
        return Result.build(null, resultCodeEnum);
    }

    //管理员 获取所有公告的列表
    @GetMapping
    public Result<PageInfo<NoticeVO>> listAllNotice(PageDTO pageDTO) {
        PageInfo<NoticeVO> pageInfo = noticeService.listAllNotice(pageDTO);
        return Result.ok(pageInfo);
    }

    //根据用户id获取公告列表
    @GetMapping("/{id}")
    public Result<PageInfo<NoticeVO>> listNoticeByUserId(@PathVariable Long id, PageDTO pageDTO) {
        PageInfo<NoticeVO> pageInfo = noticeService.listNoticeByUserId(id, pageDTO);
        return Result.ok(pageInfo);
    }

    //用户确认收到公告
    @PutMapping("/{id}")  //参数是公告id
    public Result<String> confirmReceiveNotice(@PathVariable Long id) {
        noticeService.confirmReceiveNotice(id);
        return Result.ok("确认收到公告");
    }

    //管理员 通过公告id获取所有收到和没收到公告的用户信息(姓名,邮箱,教研室名称)列表
    @GetMapping("/{id}/user")
    public Result<NoticeUserVO> listNoticeUserByNoticeId(@PathVariable Long id) {
        NoticeUserVO noticeUserVO = noticeService.listNoticeUserByNoticeId(id);
        return Result.ok(noticeUserVO);
    }

}
